using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rotempco.Core.Logging.Objects;
using Rotempco.Core.ORM.Objects;
using Rotempco.Core.Logging.Objects.Stores;
using Rotempco.Core.ORM.Objects.Stores;
using Rotempco.Core.Web.Objects.Stores;

namespace Rotempco.Core.Logic
{
    public class CoreSettingsLogic
    {
        // TODO: Create settings class in baseclass:
        /* 
         * Create in BaseClass: XXX.BaseClass.Settings;
         * 
         public class CoreSetup
         {
            public static void SetSettings()
            {
                //TODO: Implement Settings
                //EX: _CurrentDatabase = new DBConnection(@"Server=XXX;Database=XXX;User ID=XXX;Password=XXX");
                //EX: _CurrentDatabase = new DBConnection(@"Server=localhost\SQLEXPRESS;Database=XXX;Trusted_Connection=True;");

                LogSettings logSettings = new LogSettings()
                {
                    EnableDatabase = false,
                    EnableEmail = true,
                    RecipientList = new[] { "henrik@sterndorff.net" },
                    RelayHost = "192.168.32.16",
                    SenderAddress = "hje@rotempco.com",
                };

                ORMSettings ormSettings = new ORMSettings()
                {
                    DBConnectionString = @"Server=db.sterndorff.net;Database=PKITest;User ID=rtc;Password=rtc123",
                    SymmetricEncryptionKey = @"[ENCRYPTION KEY]",
                    PublicEncryptionKey = @"<RSAKeyValue><Modulus>l9heL5I8JpPtgdVJAggG1sxI0Pi6AbZ6c24Pa1SNLNyQ4rZz9q07CXyfuQYYGTeY7gHqbfCkyUX4OXnTuTgRP2cx9UgdsRskXBLRTXPQVH7Tuzam6wlqIJ2M4Y96FhvKC2/iqmfnG01UjWN/hygPOdUhtcxz7m+oayArIy6cdwk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>",
                };

                CoreSettingsLogic.SetSettings(ormSettings: ormSettings, logSettings: logSettings);
             }
         }
         * 
         */

        public static void SetSettings(LogSettings logSettings = null/*, ORMSettings ormSettings = null*/)
        {
            LogSettingsStore.Instance.LogSettings = logSettings;

            //SetDBConnectionString(ormSettings.DBConnectionString);
            //EncryptionKeyStore.Instance.PublicEncryptionKey = ormSettings.PublicEncryptionKey;
            //EncryptionKeyStore.Instance.SymmetricEncryptionKey = ormSettings.SymmetricEncryptionKey;
        }



        public static void SetDBConnectionString(string connectionString)
        {
            DatabaseSettingsStore.Instance.CurrentDatabase = new DBConnection(connectionString);
        }

        public static void SetKrustEncryptionKey(KrustKey krustKey)
        {
            EncryptionKeyStore.Instance.KrustKey = krustKey;
        }

        public static void SetPrivateDecryptionKey(string key)
        {
            EncryptionKeyStore.Instance.PrivateDecryptionKey = key;
        }

        public static void SetPublicEncryptionKey(string key)
        {
            EncryptionKeyStore.Instance.PublicEncryptionKey = key;
        }

        public static string GetPublicEncryptionKey()
        {
            return EncryptionKeyStore.Instance.PublicEncryptionKey;
        }

        public static string GetPrivateDecryptionKey()
        {
            return EncryptionKeyStore.Instance.PrivateDecryptionKey;
        }

        public static void SetSymmetricEncryptionKey(string key)
        {
            EncryptionKeyStore.Instance.SymmetricEncryptionKey = key;
        }

        public static string GetSymmetricEncryptionKey()
        {
            return EncryptionKeyStore.Instance.SymmetricEncryptionKey;
        }

        public static void ClearPrivateDecryptionKey()
        {
            EncryptionKeyStore.Instance.PrivateDecryptionKey = null;
        }

        public static void SetWebsiteName(string websiteName)
        {
            WebStore.Instance.WebsiteName = websiteName;
        }

        public static void SetDefaultWebDateFormat(string defaultWebDateFormat)
        {
            WebStore.Instance.DefaultWebDateFormat = defaultWebDateFormat;
        }

        public static void SetAddWithAndHeightToImageUrl(bool addWithAndHeightToImageUrl)
        {
            WebStore.Instance.AddWithAndHeightToImageUrl = addWithAndHeightToImageUrl;
        }

    }
}
